From 56a6edebc0cf4cb6614b1463b012443cbce1eab2 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Thu, 13 Aug 2026 16:34:42 +0000 Subject: [PATCH] Enforce, or not, COMM_IDS.Studied on WATCHES --- db/schemas/lib/triggers/create/biography_data.m4 | 15 +++++++++------ db/schemas/lib/triggers/create/watches.m4 | 13 +++++++++---- doc/src/tables/watches.m4 | 10 ++++++++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/db/schemas/lib/triggers/create/biography_data.m4 b/db/schemas/lib/triggers/create/biography_data.m4 index 5817429..e225dac 100644 --- a/db/schemas/lib/triggers/create/biography_data.m4 +++ b/db/schemas/lib/triggers/create/biography_data.m4 @@ -444,31 +444,34 @@ CREATE OR REPLACE FUNCTION biography_data_func () a_date watches.date%TYPE; a_type watches.type%TYPE; BEGIN - -- Cannot have a watch period before the individual was studied. + -- Cannot have a watch period in a study community before the + -- individual was studied. IF NEW.entrydate > OLD.entrydate THEN SELECT watches.wid, watches.commid, watches.date, watches.type INTO a_wid , a_commid , a_date , a_type FROM watches + JOIN comm_ids ON (comm_ids.commid = watches.commid) WHERE watches.animid = NEW.animid AND watches.date < NEW.entrydate + AND comm_ids.studied ORDER BY watches.date; -- consistency IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on UPDATE of BIOGRAPHY_DATA' , DETAIL = 'An individual cannot be watched -- be followed,' - || ' or have an attendance record, etc. -- before' - || ' they are under study' + || ' or have an attendance record, etc. --,' + || ' in a study group, before they are under study' || ': Key (AnimID) = (' || NEW.animid || '), Value (EntryDate) = (' || NEW.entrydate || ': Key (WATCHES.WID) = (' || a_wid - || '), Value (Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (Type) = (' + || '), Value (WATCHES.Type) = (' || a_type - || '), Value (CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/watches.m4 b/db/schemas/lib/triggers/create/watches.m4 index 19eabab..6e4a31d 100644 --- a/db/schemas/lib/triggers/create/watches.m4 +++ b/db/schemas/lib/triggers/create/watches.m4 @@ -54,7 +54,8 @@ CREATE OR REPLACE FUNCTION watches_func () cannot_change(`WATCHES', `Type') END IF; - -- Cannot have a follow date before the individual was studied + -- Cannot have a date before the individual was studied, when in + -- a study group. DECLARE this_entrydate biography_data.entrydate%TYPE; @@ -62,13 +63,17 @@ CREATE OR REPLACE FUNCTION watches_func () SELECT biography_data.entrydate INTO this_entrydate FROM biography_data + JOIN comm_ids ON (comm_ids.commid = NEW.commid) WHERE biography_data.animid = NEW.animid - AND biography_data.entrydate > NEW.date; + AND biography_data.entrydate > NEW.date + AND biography_data.birthcomm IS DISTINCT FROM NEW.commid + AND comm_ids.studied; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on ' || TG_OP || ' of WATCHES' - , DETAIL = 'An individual cannot be followed before they are' - || ' studied' + , DETAIL = 'An individual cannot be followed, in a studied' + || ' community, before they are studied, unless' + || ' born into the community' || ': Key (WID) = (' || NEW.wid || '), Value (AnimID) = (' diff --git a/doc/src/tables/watches.m4 b/doc/src/tables/watches.m4 index 1f80aa3..ceab220 100644 --- a/doc/src/tables/watches.m4 +++ b/doc/src/tables/watches.m4 @@ -238,10 +238,16 @@ The |WATCHES.Type| categories are: generate warnings when there *are* related |ARRIVALS| rows. The |WATCHES.Date| must be during a period when the watched individual -was under study. +was under study, when the community is one that was under study. +Otherwise, the |WATCHES.Date| may not be before the individual's +birthdate. This means that |WATCHES.Date| must be on or after the watched individual's -- the |WATCHES.AnimID|'s -- |BIOGRAPHY_DATA|.\ -|BIOGRAPHY_DATA.EntryDate| and on or before the watched individual's +|BIOGRAPHY_DATA.BirthDate|, and, if the |WATCHES.CommID| is that of a +|COMM_IDS|.\ |COMM_IDS.CommID| with a |true| |COMM_IDS|.\ +|COMM_IDS.Studied| value, must also be on or after the individual's +|BIOGRAPHY_DATA.EntryDate|. +And, the |WATCHES.Date| must be on or before the watched individual's |BIOGRAPHY_DATA|.\ |BIOGRAPHY_DATA.DepartDate|. .. contents:: -- 2.34.1